package com.union.core.sys.action;
import java.util.ArrayList;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
import com.union.core.IConstant;
import com.union.core.complain.model.Complain;
import com.union.core.complain.service.ComplainService;
import com.union.core.doc.model.OfficialDoc;
import com.union.core.doc.model.OfficialDocOrg;
import com.union.core.doc.pojo.OfficialDocOrgPojo;
import com.union.core.doc.pojo.OfficialDocPojo;
import com.union.core.doc.service.OfficialDocManagerService;
import com.union.core.information.model.Announcement;
import com.union.core.information.model.KnowledgeManage;
import com.union.core.information.service.AnnouncementService;
import com.union.core.information.service.KnowledgeManageService;
import com.union.core.organization.model.Personnel;

import com.union.core.organization.service.PersonnelService;

import com.union.core.sys.model.PublicSentimentModule;
import com.union.core.sys.model.Role;
import com.union.core.sys.model.SysModuleType;
import com.union.core.sys.service.PublicSentimentService;
import com.union.core.sys.service.RoleService;
import com.union.core.sys.service.SysManagerService;
import com.union.core.sys.service.SysService;

import com.opensymphony.xwork2.ActionSupport;

/**
 * ACTION类: 操作框架
 * filename: FrameAction.java
 * project:  CCTR
 * @company Hainan Jowe Technology Ltd
 * @author wangxiuwu
 * @create in 2009-5-21
 * @version 1.0
 */
public class FrameAction extends ActionSupport{
	private static final long serialVersionUID = 872316012305159L;
	private SysService sysService = SysService.getInstance();
	private static Logger log = Logger.getLogger(FrameAction.class.getName());
	private AnnouncementService announcementService;
	private Announcement announcement;
	//咨询投诉
	private ComplainService complainService;
	private List<Complain> complainList;
	private Complain complain;
	//人员
	private PersonnelService personnelService;
	private List<Personnel> personnelList;
	private Personnel personnel;
	//公文
	private OfficialDocManagerService officialDocService;
	private OfficialDocOrgPojo officialDocOrgPojo;
	//公会知识
	private KnowledgeManageService knowledgeManageService;
	private List<KnowledgeManage> knowledgeManageList;
	//舆情
	private PublicSentimentService publicSentimentService;
	private List<PublicSentimentModule> pubSentimes;
	//登录账号信息
	private Personnel person;
	private SysService sysSer;
	private int onlineCount;
	private SysManagerService sysManagerSer;
	//待办提醒
	private int pubcount;
	private int doccount;
	private int complaincount;
	//模块
	private List<SysModuleType> sysModuleTypeList;
	//角色
	private RoleService roleSer;
	private Role role;
	//权限控制
	private List<String> allPower;
	//公告
	private int org_id;
	public FrameAction(){
		announcementService = new AnnouncementService();
		knowledgeManageService=new KnowledgeManageService();
		announcement = new Announcement();
		sysSer=SysService.getInstance();
		sysManagerSer=new SysManagerService();
		complainService = new ComplainService();
		complainList = new ArrayList<Complain>();
		complain = new Complain();
		personnelService = new PersonnelService();
		personnelList = new ArrayList<Personnel>();
		personnel = new Personnel();
		officialDocService = new OfficialDocManagerService();
		officialDocOrgPojo = new OfficialDocOrgPojo();
		publicSentimentService = new PublicSentimentService();
		pubSentimes = new ArrayList<PublicSentimentModule>();
		roleSer=new RoleService();
	}
	/**
	 * 显示操作框架页面
	 * @return String
	 */
	public String sysFrame(){
		if(sysService.ifTimeOut()==false){
			return "TIMEOUT";
		}else{
			log.info("系统使用正常,操作框架页面显示正常");
			return "SUCCESS";
		}
	}
	public String menuIndex(){
		if(sysService.ifTimeOut()==false){
			return "TIMEOUT";//超时
		}
		else{
			//判断登录账号所拥有的权限
			//用户权限
			String useracl=sysService.getSessionListener().getMODULE_MGR_PURVIEW();
			String roleList=sysService.getSessionListener().getMANAGER_ROLES();
			//角色权限
				//整合角色权限
				Set<String> set = new HashSet<String>();
				if(roleList!=null && !"".equals(roleList)){
					for(String rid : roleList.split("\\|")){
						if(!"".equals(rid)){
						role=roleSer.queryById(Integer.parseInt(rid));
						String rpu=role.getRole_permissions();
						if(rpu!=null && !"".equals(rpu)){
							for(String pu : rpu.split("\\|")){
								if(!"".equals(pu)){
									set.add(pu);
								}
							}
						}
					}
					}
				}
				String abc="|";
				//整合用户与角色权限
				if(useracl!=null && !"".equals(useracl)){
					for(String pu : useracl.split("\\|")){
							if(!"".equals(pu)){
								set.add(pu);
							}
						}
				}
				//返回权限
		        for(Object s: set.toArray()){
		        	abc=abc+s.toString()+"|";
		        }
		        sysModuleTypeList = sysManagerSer.editload(abc,1);
		      
		return "SUCCESS";
		}
	}
    public String adminIndex(){
    	if(sysService.ifTimeOut()==false){
			return "TIMEOUT";//超时
		}
		else{
	    	//权限控制
			int orgId = sysService.getSessionListener().getSysManager().getPERSONNEL().getOrganization_id();
			System.out .println("aaaaaa"+orgId);
	    	allPower=sysService.getSessionListener().getAllPower();
	    	knowledgeManageList=knowledgeManageService.queryKnowledgeManageList(0, null, null, null, null, 0, 0, null, null, null, null, null, null, 0, 3);
	    	//org_id = sysService.getSessionListener().getPERSONNEL().getOrganization_id();
		    announcement = announcementService.queryNew(orgId);
		    //咨询投诉
		    personnel = sysService.getSessionListener().getPERSONNEL();
		    complaincount = complainService.quertListCount(0, null, null, personnel.getOrganization_id(), null, null, null, null, null, 1, null, null);
			//公文
		    
			officialDocOrgPojo.setOrg_id(orgId);
			officialDocOrgPojo.setSign_status(IConstant.DOC_SIGN_WILL);
			doccount = officialDocService.queryDocOrgCount(officialDocOrgPojo);
			//舆情
			//orgId=sysService.getSessionListener().getPERSONNEL().getOrganization_id();
			pubcount  = publicSentimentService.getPubSentListCount(null,null,1,-1,orgId,0,0,null);
			pubSentimes = publicSentimentService.getPubSentList(null, null, 1, -1, orgId, 0, 0, null, 0, 3);
			log.info("wull"+pubSentimes);
			log.info("wull"+pubSentimes.size());
		    return "SUCCESS";
		}
	}
    public String topIndex(){
    	if(sysService.ifTimeOut()==false){
			return "TIMEOUT";
		}else{
	    	person=sysSer.getSessionListener().getPERSONNEL();
	    	onlineCount=sysManagerSer.getOnlineUserCount();
	    	return SUCCESS;
		}
    }
	public List<KnowledgeManage> getKnowledgeManageList() {
		return knowledgeManageList;
	}
	public void setKnowledgeManageList(List<KnowledgeManage> knowledgeManageList) {
		this.knowledgeManageList = knowledgeManageList;
	}
	public Announcement getAnnouncement() {
		return announcement;
	}
	public void setAnnouncement(Announcement announcement) {
		this.announcement = announcement;
	}
	public Personnel getPerson() {
		return person;
	}
	public void setPerson(Personnel person) {
		this.person = person;
	}
	public int getOnlineCount() {
		return onlineCount;
	}
	public void setOnlineCount(int onlineCount) {
		this.onlineCount = onlineCount;
	}
	public List<Complain> getComplainList() {
		return complainList;
	}
	public void setComplainList(List<Complain> complainList) {
		this.complainList = complainList;
	}
	public Complain getComplain() {
		return complain;
	}
	public void setComplain(Complain complain) {
		this.complain = complain;
	}
	public List<Personnel> getPersonnelList() {
		return personnelList;
	}
	public void setPersonnelList(List<Personnel> personnelList) {
		this.personnelList = personnelList;
	}
	public Personnel getPersonnel() {
		return personnel;
	}
	public void setPersonnel(Personnel personnel) {
		this.personnel = personnel;
	}
	public int getPubcount() {
		return pubcount;
	}
	public void setPubcount(int pubcount) {
		this.pubcount = pubcount;
	}
	public int getDoccount() {
		return doccount;
	}
	public void setDoccount(int doccount) {
		this.doccount = doccount;
	}
	public int getComplaincount() {
		return complaincount;
	}
	public void setComplaincount(int complaincount) {
		this.complaincount = complaincount;
	}
	public List<SysModuleType> getSysModuleTypeList() {
		return sysModuleTypeList;
	}
	public void setSysModuleTypeList(List<SysModuleType> sysModuleTypeList) {
		this.sysModuleTypeList = sysModuleTypeList;
	}
	public List<PublicSentimentModule> getPubSentimes() {
		return pubSentimes;
	}
	public void setPubSentimes(List<PublicSentimentModule> pubSentimes) {
		this.pubSentimes = pubSentimes;
	}
	public List<String> getAllPower() {
		return allPower;
	}
	public void setAllPower(List<String> allPower) {
		this.allPower = allPower;
	}
	public int getOrg_id() {
		return org_id;
	}
	public void setOrg_id(int orgId) {
		org_id = orgId;
	}
}
